<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="box">全选</button>
    <br>
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <script>
        var oBox = document.getElementById('box');
        var aInput = document.getElementsByTagName('input');
        var type = true;
        oBox.onclick = function () {
            if (type) {
                for (var i = 0; i < aInput.length; i++) {
                    aInput[i].checked = true;
                }
            } else {
                for (var i = 0; i < aInput.length; i++) {
                    aInput[i].checked = false;
                }
            }
            type = !type;
        }
    </script>
</body>

</html>